package com.kolon.business.mResourceRes.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mKolonNews.controller.MResourceResDelController")
public class MResourceResDelController implements SimpleController {

	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mResourceRes/mResourceResDel.do")
	public ModelAndView controller(HttpServletRequest request,
			
		HttpServletResponse response) throws Exception {
		// 도메인
		String url = MsgUtil.getMessage("xml.url");
		// 세션 아이디 및 암호 값을 불러옴
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_USER_INFO);
		String id = (String)userMap.get("userId");
		String pw = (String)userMap.get("userPw");
		String ResourceNM = ComUtil.getNullCheck(request.getParameter("ResourceNM"), ""); // 회의실
		String ResourceNMUtf = ComUtil.getEncode(ResourceNM,"UTF-8"); // 회의실
		String ResType = ComUtil.getNullCheck(request.getParameter("ResType"));
		String ResTypeNM = ComUtil.getEncode(request.getParameter("ResTypeNM"),"UTF-8");
		String ResTypeCatid = ComUtil.getNullCheck(request.getParameter("ResTypeCatid"));
		ModelAndView modelAndView = new ModelAndView();
		StringBuffer buffer = new StringBuffer();
		buffer.append(url);			
		buffer.append("/resource_res.aspx?mode=").append("5");
		buffer.append("&id=").append(request.getParameter("id"));
		buffer.append("&userid=").append(id);
		buffer.append("&pw=").append(pw);
		// XML DOCUMENT 및 인증 처리
		ComUtil.getDocument(buffer.toString(), id, pw);
		String scriptType 	= "003";
		String message   	= "예약이 취소되었습니다.";
		String message_url = "";
		if(ResType.equals("View")){//상세보기
			message_url = "/business/mResourceRes/mResourceResView.do";
			message_url	= message_url+ "?year="+request.getParameter("strSelDate").replaceAll("-", "").substring(0, 4)
			+"&month="+request.getParameter("strSelDate").replaceAll("-", "").substring(4, 6)+"&day="+request.getParameter("strSelDate").replaceAll("-", "").substring(6, 8)
			+"&strResourceType="+request.getParameter("strResourceType")+"&strResourceID="+request.getParameter("strResourceID")
			+"&ResourceNM="+ResourceNMUtf;
		}else{ //리스트형 보기
			message_url = "/business/mResourceRes/mResourceResDetailList.do?ResourceType=&catid="+ResTypeCatid;
			message_url	= message_url+ "&year="+request.getParameter("strSelDate").replaceAll("-", "").substring(0, 4)
			+"&month="+request.getParameter("strSelDate").replaceAll("-", "").substring(4, 6)+"&day="+request.getParameter("strSelDate").replaceAll("-", "").substring(6, 8)
			+"&type="+request.getParameter("strResourceType")+"&strResourceID="+request.getParameter("strResourceID")
			+"&ResourceNM="+ResTypeNM;
		}
		// 리턴
		modelAndView.addObject("ResType", ResType);
		modelAndView.addObject("scriptType", scriptType);
		modelAndView.addObject("message", message);
		modelAndView.addObject("message_url", message_url);
		modelAndView.setViewName("/business/common/alert");
		return modelAndView;
	}

}